package com.teach;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Arrays;

/**
 * <pre>
 * - IO编程模板
 * Author : J.L.Zhou
 * E-Mail : 2233875735@qq.com
 * Tel : 151 1104 7708
 * Date : 2021-4-26 9:54:05
 * Version : 1.0
 * Copyright 2021 jlzhou.top Inc. All rights reserved.
 * Warning: this content is only for internal circulation of the company.
 *          It is forbidden to divulge it or use it for other commercial purposes.
 * </pre>
 */
public class Test3 {

	public static void main1(String[] args) {
		
		//IO中的流使用完后，一定要关闭释放资源
		/**
		 * in.txt
		 * ABC\nabc 65,66,67,13,10,97,98,99
		 */
		File f1 = new File("d:/upload/in.txt");
		InputStream in = null;
		try {
			in = new FileInputStream(f1);
			int len = 0;
			byte[] bs = new byte[1024];
			while((len = in.read(bs)) > -1) {
				System.out.println(len+Arrays.toString(bs));
			}
		}catch (Exception e) {
			System.out.println("IO异常处理");
			e.printStackTrace();
		}finally {
			try {
				in.close();
			} catch (Exception e) {
			}
		}
	}
	
	public static void main(String[] args) {
		//IO中的流使用完后，一定要关闭释放资源
		//JDK1.7+ 资源的自动释放
		//implements Closeable
		//Closeable extends AutoCloseable
		/**
		 * in.txt
		 * ABC\nabc 65,66,67,13,10,97,98,99
		 */
		File f1 = new File("d:/upload/in.txt");
		try(
			InputStream in = new FileInputStream(f1);
		) {
			
			int len = 0;
			byte[] bs = new byte[1024];
			while((len = in.read(bs)) > -1) {
				System.out.println(len+Arrays.toString(bs));
			}
		}catch (Exception e) {
			System.out.println("IO异常处理");
			e.printStackTrace();
		}
	}
}
